<template>
	<view class="content">

			
		<view class="icon-box">
			<view class="icon">
				<image :src="img" mode='aspectFill'></image>
			</view>
			<button class="up-icon" @tap="ChooseImage">+</button>
			
		</view>
			
		
		<view class="input-group">
			<view class="input-row border">
				<m-input type="text" focus clearable v-model="user_name" placeholder="请输入账号"></m-input>
			</view>
			<view class="input-row border">
				<m-input type="password" displayable v-model="password" placeholder="请输入密码"></m-input>
			</view>
<!-- 			<view class="input-row">
				<m-input type="text" clearable v-model="email" placeholder="请输入邮箱"></m-input>
			</view> -->
		</view>
		<view class="btn-row">
			<button type="primary" class="primary" @tap="register">注册</button>
		</view>

	</view>
</template>

<script>
	import mInput from '../component/m-input.vue';
	import data from '../../datas/data.json'
	export default {
		components: {
			mInput
		},
		data() {
			return {
				user_name: '',
				password: '',
				email: '',
				icon:"",
				characters:[],
				img:'',
				up_img:''

			}
		},
		methods: {

			register() {
				/**
				 * 客户端对账号信息进行一些必要的校验。
				 * 实际开发中，根据业务需要进行处理，这里仅做示例。
				 */
				// if (this.user_name.length < 5) {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: '账号最短为 5 个字符'
				// 	});
				// 	return;
				// }
				// if (this.password.length < 6) {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: '密码最短为 6 个字符'
				// 	});
				// 	return;
				// }
				// if (this.email.length < 3 || !~this.email.indexOf('@')) {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: '邮箱地址不合法'
				// 	});
				// 	return;
				// }
				if(this.icon.length==0){
					this.icon="https://ossweb-img.qq.com/images/lol/web201310/skin/big10001.jpg";
				}
				const user = {
					"user_id":Math.random().toString(36).substr(2),
					user_name: this.user_name,
					password: this.password,
					"icon":this.icon,
					"characters":this.characters,
					"focused_users":[],
					"focus_count":0,
					"is_focused_users":[],
					"is_focus_count":0
				}

				data.users.push(user);
				console.log(data);
				uni.showToast({
					title: '注册成功',
				});

				uni.navigateBack({
					delta: 1
				});
			},
			  // 图片上传
			ChooseImage:function() {
				var that=this;
				uni.chooseImage({
				  count: 1, //默认9
				  sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
				  sourceType: ['album'], //从相册选择
				  success: (res) => {

					uni.getFileSystemManager().readFile({
					filePath: res.tempFilePaths[0],
					encoding: 'base64',
					success: r => {

							let tmp="data:image/png;base64,"+r.data;
							that.icon=tmp;
						}
					})					  


					this.img=res.tempFilePaths[0]
				  }
				});
			},
			  // 删除照片

		}
	}
</script>

<style scoped>
	@import "../component/m-icon/m-icon.css";
	/*每个页面公共css */
	page {
		min-height: 100%;
		display: flex;
		font-size: 16px;
	}

	/* #ifdef MP-BAIDU */
	page {
		width: 100%;
		height: 100%;
		display: block;
	}

	swan-template {
		width: 100%;
		min-height: 100%;
		display: flex;
	}

	/* 原生组件模式下需要注意组件外部样式 */
	custom-component {
		width: 100%;
		min-height: 100%;
		display: flex;
	}

	/* #endif */

	/* #ifdef MP-ALIPAY */
	page {
		min-height: 100vh;
	}

	/* #endif */

	/* 原生组件模式下需要注意组件外部样式 */
	m-input {
		width: 100%;
		/* min-height: 100%; */
		display: flex;
		flex: 1;
	}

	.content {
		display: flex;
		flex: 1;
		flex-direction: column;
		background-color: #f9f9f9;
		padding: 10px;
	}

	.input-group {

		margin-top: 20px;
		position: relative;
	}

	/* .input-group::before {
		position: absolute;
		right: 0;
		top: 0;
		left: 0;
		height: 1px;
		content: '';
		-webkit-transform: scaleY(.5);
		transform: scaleY(.5);
		background-color: #c8c7cc;
	}

	.input-group::after {
		position: absolute;
		right: 0;
		bottom: 0;
		left: 0;
		height: 1px;
		content: '';
		-webkit-transform: scaleY(.5);
		transform: scaleY(.5);
		background-color: #c8c7cc;
	} */

	.input-row {
		box-shadow: #ebedf2 0px 15px 33px;
		display: flex;
		background: #FFFFFF;
		height: 50px;
		flex-direction: row;
		position: relative;
		font-size: 18px;
		line-height: 40px;
		border-radius: 20px 20px;
	}
	.input-row:not(:first-child){
		margin-top:6%;
	}
	.input-row .title {
		width: 72px;
		padding-left: 15px;
	}

	.input-row.border::after {
		position: absolute;
		right: 0;
		bottom: 0;
		left: 8px;
		height: 1px;
		content: '';
		-webkit-transform: scaleY(.5);
		transform: scaleY(.5);
		background-color: #c8c7cc;
	}

	.btn-row {
		margin-top: 25px;
		padding: 10px;
	}

	button.primary {
		background: linear-gradient(#2b7ffc, #4c9cfd);
		font-size: 20px;
		border-radius: 20px;
	}

	.logo{
		margin-left: 38%;
		margin-top:11%;
		margin-bottom: 3%;
		width: 90px;
		height:70px;
	}
	.action-row {
		display: flex;
		flex-direction: row;
		justify-content: center;
		
		margin-top: 7%;
	}
	.forget{
		margin-top: 7%;
	}
	.forget-nav{
		margin-left: 70%;
	}
	.top-nav{
		width: 107%;
		height: 40px;
		margin-left: -3%;
		margin-top: -3%;
		display: flex;
		flex-direction: row;
		justify-content: center;
		background: #FFFFFF;
	}
	.top-nav navigator {
		color: #2478fc;
		font-size: 20px;
		padding: 0 10px;
	}
	.action-row navigator {
		color: #007aff;
		padding: 0 10px;
	}

	.oauth-row {
		display: flex;
		flex-direction: row;
		justify-content: center;
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
	}

	.oauth-image {
		position: relative;
		width: 50px;
		height: 50px;
		border: 1px solid #dddddd;
		border-radius: 50px;
		margin: 0 20px;
		background-color: #ffffff;
	}

	.oauth-image image {
		width: 30px;
		height: 30px;
		margin: 10px;
	}

	.oauth-image button {
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		opacity: 0;
	}
	.icon-box{
		margin: 0 auto;
		width: 80%;
	}
	.icon{
		margin: 0 auto;
		width: 70px;
		height: 70px;
		background: #e8eaf0;
		border-radius: 50% 50%;
	}
	.icon image{
		width: 70px;
		height: 70px;
		border-radius: 50% 50%;		
	}
	.up-icon{
		margin-top: 4%;
		width: 50px;
		height: 50px;
		border: #000000 solid 1px;
		background: #F1F1F1;
	}
</style>
